<template>
  <van-config-provider :theme-vars="themeVars" theme-vars-scope="global">
    <RouterView />

    <!-- <TabBarCmp /> -->
  </van-config-provider>
</template>

<script setup>
import { useHead } from '@unhead/vue'

useHead({
  title: '猫眼电影'
})

import { reactive, onMounted, } from 'vue'
import { getUserGeolocation } from '@/tools/index.js'
import { fetchCityByLatLng } from '@/api/index.js'

import { useStore } from '@/stores/index.js'
const store = useStore()

const themeVars = reactive({
  navBarHeight: '50.5px',
  navBarBackground: '#e54847',
  navBarTextColor: '#fff',
  navBarTitleTextColor: '#fff',
  navBarIconColor: '#fff',
  navBarTitleFontSize: '18px',

  dropdownMenuTitleActiveTextColor: '#e54847',
  dropdownMenuOptionActiveColor: '#e54847',

  tabActiveTextColor: '#e54847',
  tabsBottomBarColor: '#e54847',

  sidebarSelectedTextColor: '#e54847',
  sidebarSelectedBorderColor: '#e54847',

  treeSelectItemActiveColor: '#e54847',

  // toastBackground: 'rgba(0,0,0,0.7)!important',
})

onMounted(async () => {

  let latitude = 0
  let longitude = 0

  try {
    // 查询用户经纬度
    const Geolocation = await getUserGeolocation()
    console.log('Geolocation:', Geolocation) // {latitude: 20.010147880553536, longitude: 110.36247460305897}

    latitude = Geolocation.latitude;
    longitude = Geolocation.longitude;
  } catch (error) {
    console.error('Error getting user geolocation:', error);

  }


  // 保存经纬度
  store.setGeolocation(latitude, longitude)

  const res = await fetchCityByLatLng(latitude, longitude)
  //  设定当前访问城市
  if (res.error) {
    store.setCurrentCity({ id: 94, nm: '海口' })
    console.error(res.error.message)
  } else {
    store.setCurrentCity({ id: res.data.id, nm: res.data.city })
  }

});



</script>

<style>
body {
  background-color: #f0f0f0 !important;
}
</style>
